package pe.gob.sedapal.scmultimedia.rcp.view.estadocuenta;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseAdapter;

import pe.gob.sedapal.scmultimedia.config.ApplicationContext;
import pe.gob.sedapal.scmultimedia.sessionbean.DataSessionBean;
import pe.gob.sedapal.scmultimedia.util.Constante;
import pe.gob.sedapal.scmultimedia.util.Messages;
import pe.gob.sedapal.scmultimedia.wb.swt.ResourceManager;
import org.eclipse.wb.swt.SWTResourceManager;

public class ConsultaEstadoCuentaView extends ViewPart {
	
	private DataSessionBean dataSessionBean;
	
	public static final String ID = Constante.ID_CONSULTA_ESTADO_CUENTA_VIEW;
	//public static final String ID = "scmultimedia.consultaEstadoCuentaView";
	
	private Label btnSuministro;
	private Label btnDireccion; 
	
	public ConsultaEstadoCuentaView() {
		// TODO Auto-generated constructor stub
		dataSessionBean = (DataSessionBean)ApplicationContext.getBean(DataSessionBean.class);
		dataSessionBean.limpiar();
	}

	@Override
	public void createPartControl(Composite parent) {
		parent.setBackgroundImage(ResourceManager.getPluginImage("scmultimedia", Constante.RUTA_IMG_FONDO_SEDAPAL));

		parent.setBackgroundMode(SWT.INHERIT_DEFAULT);
		parent.setLayout(null);
		
		Label imgLogo = new Label(parent, SWT.NONE);
		imgLogo.setImage(ResourceManager.getPluginImage("scmultimedia", Constante.RUTA_IMG_LOGO_SEDAPAL_INTERNO));
		imgLogo.setBounds(635, 10, 192, 84);
		
		Label imgBarralbl = new Label(parent, SWT.NONE);
		imgBarralbl.setImage(ResourceManager.getPluginImage("scmultimedia", Constante.RUTA_IMG_BARRA));
		imgBarralbl.setBounds(10, 61, 736, 8);
		
		btnSuministro = new Label(parent, SWT.CENTER);
		btnSuministro.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDown(MouseEvent e) {
				IWorkbenchPage pagina = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
				IViewReference vistaActual = pagina.findViewReference(ConsultaEstadoCuentaView.ID);
				
				pagina.hideView(vistaActual);
				
				try{
					pagina.showView(BuscarSuministroView.ID);
				}catch(Exception ex){
					ex.printStackTrace();
				}
			}
		});
		btnSuministro.addMouseTrackListener(new MouseTrackAdapter() {
			@Override
			public void mouseEnter(MouseEvent e) {
				btnSuministro.setImage(ResourceManager.getPluginImage("scmultimedia", Constante.RUTA_IMG_BOTON_LATERAL_SALDO_SUMINISTRO));
			}
			@Override
			public void mouseExit(MouseEvent e) {
				btnSuministro.setImage(ResourceManager.getPluginImage("scmultimedia", Constante.RUTA_IMG_BOTON_LATERAL_SALDO_SUMINISTRO_OFF));
			}
		});
		btnSuministro.setImage(ResourceManager.getPluginImage("scmultimedia", Constante.RUTA_IMG_BOTON_LATERAL_SALDO_SUMINISTRO));
		btnSuministro.setBounds(192, 151, 372, 108);
	//	btnSuministro.setText("Por N° de Suministro");
		
		btnDireccion = new Label(parent, SWT.CENTER);
		btnDireccion.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDown(MouseEvent e) {
				IWorkbenchPage pagina = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
				IViewReference vistaActual = pagina.findViewReference(ConsultaEstadoCuentaView.ID);
				
				pagina.hideView(vistaActual);
				
				try{
					pagina.showView(BuscarDireccionView.ID);
				}catch(Exception ex){
					ex.printStackTrace();
				}
			}
		});
		btnDireccion.addMouseTrackListener(new MouseTrackAdapter() {
			@Override
			public void mouseEnter(MouseEvent e) {
				btnDireccion.setImage(ResourceManager.getPluginImage("scmultimedia", Constante.RUTA_IMG_BOTON_LATERAL_SALDO_DIRECCION_A));
			}
			@Override
			public void mouseExit(MouseEvent e) {
				btnDireccion.setImage(ResourceManager.getPluginImage("scmultimedia", Constante.RUTA_IMG_BOTON_LATERAL_SALDO_DIRECCION_A_OFF));
			}
		});
		btnDireccion.setImage(ResourceManager.getPluginImage("scmultimedia", Constante.RUTA_IMG_BOTON_LATERAL_SALDO_DIRECCION_A));
		btnDireccion.setBounds(192, 319, 372, 108);
	//	btnDireccion.setText("Por Dirección");
		
		Label lblTituloCuentas = new Label(parent, SWT.NONE);
		lblTituloCuentas.setFont(SWTResourceManager.getFont("FreeSans", 17, SWT.BOLD | SWT.ITALIC));
		lblTituloCuentas.setForeground(org.eclipse.wb.swt.SWTResourceManager.getColor(51, 102, 153));
		lblTituloCuentas.setBounds(10, 22, 295, 24);
		lblTituloCuentas.setText(Messages.buscarDireccion_titulo);

	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub

	}
}
